// mfcdll.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "mfcdll.h"
//#include "network.h"
#include "comdef.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
//	Note!
//
//		If this DLL is dynamically linked against the MFC
//		DLLs, any functions exported from this DLL which
//		call into MFC must have the AFX_MANAGE_STATE macro
//		added at the very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

/////////////////////////////////////////////////////////////////////////////
// CMfcdllApp

BEGIN_MESSAGE_MAP(CMfcdllApp, CWinApp)
	//{{AFX_MSG_MAP(CMfcdllApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMfcdllApp construction

CMfcdllApp::CMfcdllApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMfcdllApp object

CMfcdllApp theApp;
__declspec(dllexport) long __stdcall bstrToarr1(const VARIANT FAR& vbstr,double * p,long n1)
{
  switch  (vbstr.vt)
  {
  case VT_BSTR:
  	  memcpy(p,vbstr.bstrVal,n1*4);
	  return(n1);
  case VT_UI1 | VT_ARRAY:
	memcpy(p,vbstr.parray->pvData,n1*4);
	return(n1);
  default:
	return(-1);
  }
}
__declspec(dllexport) void __stdcall mymemcpy(char * des,char * src,long n1)
{
	  memcpy(des,src,n1);
}
__declspec(dllexport) long __stdcall bstrToarr(BYTE * b,float * varr,long n)
{
	  memcpy(b,varr,n*4);
	  return(n);
}
__declspec(dllexport) long __stdcall arrTobstr(BYTE * b,float * varr,long n)
{
	  memcpy(varr,b,n*4);
	  return(n);
}
__declspec(dllexport) BOOL __stdcall smooth3(VARIANT & x,VARIANT & y,long n,long bAN,double * a,double *b ,long &bcount)
{
	  double *px;
	  double *py;
	  if (x.vt==(VT_R4 | VT_ARRAY))
	  {
		  px=(double *)x.parray->pvData;
	  }
	  else
	  {
		  return(FALSE);
	  }
	  if (y.vt==(VT_R4 | VT_ARRAY))
	  {
		  py=(double *)y.parray->pvData;
	  }
	  else
	  {
		  return(FALSE);
	  }

	  if(n < bAN * 2 + 1){
		  return(FALSE);
	  }
	long i;
	bcount = 0;
	long j;
	for(i = bAN;i< n - bAN;i++)
	{
	   a[bcount] = px[i];
	   for( j = i - bAN ;j< i + bAN+1;j++)
	   {
		  b[bcount] = b[bcount] + py[j];
	   }
	   b[bcount] = b[bcount] / (2 * bAN + 1);
	   bcount = bcount + 1;
	}
	return(TRUE);
}
__declspec(dllexport) void __stdcall koujixian(double *y ,long n)
{
	if(n<1) return;
	long i;
	double  y0;
	y0=*y;
	for(i = 1;i< n;i++)
	{
		if(y0>y[i]) y0=y[i];
	}
	for(i =0;i< n;i++)
	{
		y[i]=y[i]-y0+.0000001;
	}
}

